package com.fqgj.sentry.controller.mc;


import com.fqgj.sentry.biz.mc.ConfigBusiness;
import com.fqgj.sentry.common.annotations.ParamsValidate;
import com.fqgj.sentry.common.cache.RequestLocalInfo;
import com.fqgj.sentry.common.response.ApiOutput;
import com.fqgj.sentry.common.utils.ApiPage;
import com.fqgj.sentry.controller.mc.request.AddAlarmManRequest;
import com.fqgj.sentry.controller.mc.request.AlarmPageVo;
import com.fqgj.sentry.controller.mc.request.ModifyAlarmManRequest;
import com.fqgj.sentry.biz.mc.domain.AddAlarmManInfo;
import com.fqgj.sentry.biz.mc.domain.ModifyAlarmManInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by ykpbean kangping.ying@yuntu-inc.com
 *
 * @description
 * @create 2017-07-19 上午10:06
 */

@RestController
@RequestMapping("/config")
public class ConfigController {

    @Autowired
    private ConfigBusiness configBusiness;

    @RequestMapping(value = "/add/alarm", method = RequestMethod.POST)
    public ApiOutput addAlarmMan(@RequestBody AddAlarmManRequest alarmManRequest) {
        AddAlarmManInfo addAlarmManInfo = new AddAlarmManInfo();
        BeanUtils.copyProperties(alarmManRequest, addAlarmManInfo);
        addAlarmManInfo.setMerchantId(RequestLocalInfo.getCurrentMerchantId());
        configBusiness.addAlarmMan(addAlarmManInfo);
        return new ApiOutput<>();
    }


    @RequestMapping(value = "/modify/alarm", method = RequestMethod.POST)
    public ApiOutput modifyAlarmMan(@RequestBody ModifyAlarmManRequest alarmManRequest) {
        ModifyAlarmManInfo modifyAlarmManInfo = new ModifyAlarmManInfo();
        BeanUtils.copyProperties(alarmManRequest, modifyAlarmManInfo);
        modifyAlarmManInfo.setMerchantId(RequestLocalInfo.getCurrentMerchantId());
        configBusiness.modifyAlarmMan(modifyAlarmManInfo);
        return new ApiOutput<>();
    }


    @RequestMapping(value = "del/alarm", method = RequestMethod.POST)
    public ApiOutput delAlarmMan(@RequestParam Long manId) {
        configBusiness.delAlarmMan(RequestLocalInfo.getCurrentMerchantId(), manId);
        return new ApiOutput<>();
    }


    @ParamsValidate
    @RequestMapping(value = "/list/alarm", method = RequestMethod.POST)
    public ApiOutput queryListAlarmManForPage(@RequestBody AlarmPageVo alarmPageVo) {
        ApiPage apiPage = configBusiness.queryAlarmManForPage(RequestLocalInfo.getCurrentMerchantId(), alarmPageVo.getName(), alarmPageVo.getEmail(), alarmPageVo.getPageNum(), alarmPageVo.getPageSize());
        return new ApiOutput<>("alarmManInfo", apiPage);
    }
}
